﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Bronze.XXTong.DAL.DatabaseSpecific;
using Bronze.XXTong.DAL.Linq;

namespace Bronze.XXT.BLL
{
    /// <summary>
    /// 关于用户刷卡的操作
    /// </summary>
    public class UserICCard
    {
        /// <summary>
        /// 判断卡的类型
        /// </summary>
        /// <param name="strICCardNum"></param>
        /// <returns>0 无效 (>0 有效) 1为学生 2为教师卡</returns>
        public static int CheckICCard(string strICCardNum) 
        {
            int intResult = 0;
            using (DataAccessAdapter adapter = new DataAccessAdapter()) 
            {
                LinqMetaData metaData = new LinqMetaData(adapter);
                if (metaData.Student.Any(o => o.FIcCardNumber == strICCardNum)) 
                {
                    intResult = 1;
                }
                else if (metaData.UserInfo.Any(o => o.FIcCardNumber == strICCardNum)) 
                {
                    intResult = 2;
                }
            }
            return intResult;
        }

        /// <summary>
        /// 根据学生学生IC卡号获取亲情号码
        /// </summary>
        /// <param name="strICCardNum">IC卡号</param>
        /// <returns>
        /// object[] 0 称呼 ,1 名称 ,2 亲情号码1 ,3 亲情号码2 ,4 亲情号码3
        /// </returns>
        public static List<object[]> GetFamilyNumsByStuId(string strICCardNum)
        {
            List<object[]> nums = null;
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                LinqMetaData metaData = new LinqMetaData(adapter);
                nums = (from stu in metaData.Student
                            join sh in metaData.StuHomeMember
                            on stu.FStuID equals sh.FStuID
                            where stu.FIcCardNumber == strICCardNum
                            select new object[]
                            {
                                sh.FMemberType,
                                sh.FMemberName,
                                sh.FFamilyNum1,
                                sh.FFamilyNum2,
                                sh.FFamilyNum3
                            }).ToList();
            }
            return nums;
        }
    }
}
